# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface

from demo_59.items import ZuFangItem
from demo_59.estools import Estools

#自定义类,保存数据到es
class EsData():
    #实例化连接对象
    def __init__(self):
        self.es = Estools()


    #数据存储
    def process_item(self,item,spider):
        #数据类型判断
        if isinstance(item,ZuFangItem):
            data = dict(item)
            #调es工具类的存储函数
            self.es.insert_data(data)
            return item
